﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace LogWatcherX
{
    public class BooleanToWrapperConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return DoConversion(value, targetType);
        }

        private static object DoConversion(object value, Type targetType)
        {
            if (targetType.Equals(typeof (TextWrapping)))
            {
                if ((bool) value)
                    return TextWrapping.Wrap;

                return TextWrapping.NoWrap;
            }
            else
            {
                switch ((TextWrapping) value)
                {
                    case TextWrapping.NoWrap:
                        return false;
                    case TextWrapping.WrapWithOverflow:
                    case TextWrapping.Wrap:
                        return true;
                    default:
                        throw new NotImplementedException();
                }
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return DoConversion(value, targetType);
        }
    }
}
